package com.ruoyi.web.controller.zsix;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.form.FormEntity;
import com.ruoyi.common.core.domain.form.FormSortEntity;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.zsix.service.IFormMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/form")
public class FormMapController extends BaseController {
    @Autowired
    private IFormMapService formMapService;

    /**
     * 表单列表
     * @return
     */
    @Log(title = "获取表单列表" , businessType = BusinessType.EXPORT)
    @PostMapping("/formList")
    public TableDataInfo formList(@RequestBody FormEntity formInfo){
        startPage();
        List<FormEntity> list = formMapService.formList(formInfo);
        return getDataTable(list);
    }

    /**
     * 获取表单树
     * @return
     */
    @Log(title = "获取表单树" , businessType = BusinessType.EXPORT)
    @GetMapping("/getFormTree")
    public AjaxResult getFormTree(){
        return success(formMapService.getFormTree());
    }
//    /**
//     * 获取表单树，增加时使用
//     * @return
//     */
//    @OperLog(operModul = "表单操作" , operType = LogConst.OTHER , operDesc = "获取表单树")
//    @GetMapping("/form/getFormTreeByAdd")
//    public ResultRes getFormTreeByAdd(){
//        return ResultRes.success(formMapService.getFormTreeByAdd());
//    }
//    @OperLog(operModul = "表单操作" , operType = LogConst.OTHER , operDesc = "获取/查看单个表单")
//    @GetMapping("/form/getFormEntity")
//    public ResultRes getFormEntity(HttpServletResponse response,
//                                   @RequestParam("id") String id){
//        FormEntity formEntity=formMapService.getFormEntity(id);
//        if(formEntity!=null) {
//            return ResultRes.success(formEntity);
//        }
//        else{
//            return ResultRes.error("不存在id为["+id+"]的对象。");
//        }
//    }

    /**
     * 创建/修改表单
     * @param param
     * @return
     */
    @Log(title = "创建/修改表单" , businessType = BusinessType.EXPORT)
    @PostMapping("/editForm")
    public AjaxResult editForm(@RequestBody JSONObject param){
        return success(formMapService.editForm(param));
    }

    /**
     * 删除表单
     * @param formId
     * @return
     */
    @Log(title = "删除表单" , businessType = BusinessType.EXPORT)
    @PostMapping("/deleteForm")
    public AjaxResult deleteForm(@RequestParam("id") String formId){
        return success(formMapService.deleteForm(formId));
    }
    @Log(title = "获取表单分类列表" , businessType = BusinessType.EXPORT)
    @GetMapping("/formSortList")
    public AjaxResult formSortList(){
        return success(formMapService.formSortList());
    }
    /**
     * 增加表单分类
     * @param formSortEntity
     * @return
     */
    @Log(title = "增加表单分类" , businessType = BusinessType.EXPORT)
    @PostMapping("/addFormSort")
    public AjaxResult addFormSort(@RequestBody FormSortEntity formSortEntity){
        return success(formMapService.addFormSort(formSortEntity));
    }

    /**
     * 删除表单分类
     * @param formSortEntity
     * @return
     */
    @Log(title = "删除表单分类" , businessType = BusinessType.EXPORT)
    @PostMapping("/deleteFormSort")
    public AjaxResult deleteFormSort(@RequestBody FormSortEntity formSortEntity){
        return success(formMapService.deleteFormSort(formSortEntity));
    }

    /**
     * 更新表单分类信息
     * @param formSortEntity
     * @return
     */
    @Log(title = "更新表单分类信息" , businessType = BusinessType.EXPORT)
    @PostMapping("/updateFormSort")
    public AjaxResult updateFormSort(@RequestBody FormSortEntity formSortEntity){
        return success(formMapService.updateFormSort(formSortEntity));
    }
//    @OperLog(operModul = "表单操作" , operType = LogConst.OTHER , operDesc = "获取表单数据")
//    @GetMapping("/form/getGenerWork")
//    public ResultRes getGenerWork(HttpServletResponse response,
//                                  @RequestParam("id") String id){
//        try{
//            return ResultRes.success(formMapService.getGenerWork(id));
//        }
//        catch (Exception ex){
//            return ResultRes.error(ex.getMessage());
//        }
//    }
//    @OperLog(operModul = "表单操作" , operType = LogConst.DELETE , operDesc = "删除表单数据")
//    @PostMapping("/form/deleteGenerWork")
//    public ResultRes deleteGenerWork(@RequestBody JSONObject param){
//        String id=param.getString("frmId");
//        String list=param.getString("list");
//        String msg=formMapService.deleteGenerWork(id,list);
//        if(msg.equals("suess")){
//            return ResultRes.success("删除成功。");
//        }
//        else{
//            return ResultRes.error(msg);
//        }
//    }
}
